linear regression
Tutorials
Linear Regression with Python | Connor Johnson
hr.icon
numpy.polyfit
code:python
np.polyfit(x,y,deg=1)
hr.icon
scipy.stats.linregress
scipy.optimize.curve_fit
code:python
from scipy import optimize
# Define a model function
def model_func(x, a0, a1):
return a0 + (a1*x)
param_opt, param_cov = optimize.curve_fit(model_func, x_data, y_data)
a0 = param_opt0 # a0 is the intercept in y = a0 + a1*x a1 = param_opt1 # a1 is the slope in y = a0 + a1*x hr.icon
examples
pandas pandas で 回帰分析 - tetsunosukeのnotebook hr.icon
Statsmodels Examples
Linear Regression
Fitting models using R-style formulas
Examples
code:python
import pandas as pd
from statsmodels.formula.api import ols
df = pd.DataFrame(dict(x_column=x_data, y_column=y_data))
# Pass data and formula into ols(), use and .fit() the model to the data
model_fit = ols(formula="y_column ~ x_column", data=df).fit()
# Use .predict(df) to get y_model values, then over-plot y_data with y_model
y_model = model_fit.predict(df)
# Extract the a0, a1 values from model_fit.params
uncertainty_in_slope = model_fit.bse'x_column Regression beteeen the Kushimoto-Uragami sea-level difference and Kuroshio-Path latitude (on Google Colab)
hr.icon
sklearn.linear_model.LinearRegression
Examples
code:python
from sklearn.linear_model import LinearRegression
# Initialize a general model
model = LinearRegression(fit_intercept=True)
# Load and shape the data
x_data = x_raw.reshape(len(y_raw),1)
y_data = y_raw.reshape(len(y_raw),1)
# Fit the model to the data
model_fit = model.fit(x_data, y_data)
# Extract the linear model parameters
intercept = model.intercept_0 # Extract the linear model parameters
intercept = model.intercept_0 MetPy Mondays `#182 - Linear Regression with Scikit-Learn - Basic Machine Learning : Unidata Developer's Blog This week we explore some machine learning basics on a new MetPyMonday!
sklearn.linear_model.Ridge
Tutorials
一般化線形モデルのラッソとリッジでの推定量算出・予測 - Qiita
Paid tutorials
Machine Learning for Time Series Data in Python | DataCamp
hr.icon
Patsy: Describing statistical models in Python using symbolic formulas hr.icon
See also